<template>
  <div class = "container1">
    <div class="input-group mb-3">
      <input type="text" class="form-control" placeholder="输入客户名" aria-label="Recipient's username"
             aria-describedby="button-addon2" v-model="this.customerName">

      <button class="btn btn-outline-secondary" type="button" id="button-addon2" @click="getByName">客户名查询</button>
      <button type="button" class="btn btn-outline-primary" @click="getZeroList">未审核</button>
      <button type="button" class="btn btn-outline-primary" @click="getOneList">已同意</button>
      <button type="button" class="btn btn-outline-primary" @click="getTwoList">已驳回</button>
    </div>
  </div>
  <div v-for="(item, index) in allList" :key="item.defaultApplication.applicationNumber">
    <div class="container2">
      <table class="table">
        <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">客户名</th>
          <th scope="col">外部等级</th>
          <th scope="col">严重性</th>
          <th scope="col">申请时间</th>
          <th scope="col">审核状态</th>
          <th scope="col">审核时间</th>
          <th scope="col">审核人</th>
          <th scope="col">重生状态</th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <th scope="row">{{++index}}</th>
          <td>{{item.customer.customerName}}</td>
          <td>{{item.customer.rank}}</td>
          <td>{{item.defaultApplication.severity}}</td>
          <td>{{item.defaultApplication.applicationTime}}</td>
          <td>{{item.defaultApplication.approvementStatus==0 ? "未审核":(item.defaultApplication.approvementStatus==1?'已同意':'已驳回') }}</td>
          <td>{{item.defaultApplication.approvementTime}}</td>
          <td>{{item.defaultApplication.defaultApproverName}}</td>
          <td>{{item.defaultApplication.redoStatus==0 ? "未重生":"已重生"}}</td>
        </tr>
        </tbody>
      </table>
      <div style="width: 650px;display: inline-block">
        <h6>违约原因</h6>
        <div v-for="(item, index) in item.defaultReasonList" :key="index">
            ({{++index}})   {{item}}
        </div>
      </div>
      <div style="width: 650px;display: inline-block">
        <h6>重生申请</h6>
        <select class="form-select" aria-label="Default select example" :id="addSelect(index)">
          <option value="1">正常结算后解除</option>
          <option value="2">在其他金融机构违约解除，或外部评级显示为非违约级别</option>
          <option value="3">计提比例小于设置界限</option>
          <option value="4">连续 12 个月内按时支付本金和利息</option>
          <option value="5">客户的还款意愿和还款能力明显好转，已偿付各项逾期本金、逾期利息和其他费用（包括罚息等），且连续 12 个月内按时支付本金、利息</option>
          <option value="6">导致违约的关联集团内其他发生违约的客户已经违约重生，解除关联成员的违约设定</option>
        </select>
        <button type="button" class="btn btn-outline-success" @click="submitRedo(index,item)">提交重生申请</button>
      </div>
    </div>
  </div>


</template>

<script>
export default {
  name: 'ApplicationDefaultApplication',
  data(){
    return {
      allList:[],
      customerName:"",

    }
  },

  methods: {

    async getAllList(){
      const {data: res} = await this.$http.get('/defaultApplication/applicantAll?applicantAccount='+localStorage.getItem("applicantAccount"))
      this.allList=res.data
    },
    async getZeroList(){
      const {data: res}= await this.$http.get('/defaultApplication/applicantSearchByStatusZero?applicantAccount='+localStorage.getItem("applicantAccount"))
      this.allList=res.data
    },
    async getOneList(){
      const {data: res}= await this.$http.get('/defaultApplication/applicantSearchByStatusOne?applicantAccount='+localStorage.getItem("applicantAccount"))
      this.allList=res.data
    },
    async getTwoList(){
      const {data: res}= await this.$http.get('/defaultApplication/applicantSearchByStatusTwo?applicantAccount='+localStorage.getItem("applicantAccount"))
      this.allList=res.data
    },
    async getByName(){
      const {data: res}= await this.$http.get('/defaultApplication/applicantSearchByName?applicantAccount='+localStorage.getItem("applicantAccount")
          +"&customerName="+this.customerName)
      this.allList=res.data
    },
    addSelect(i){
      return "select"+i
    },

    async submitRedo(index,item){
      console.log(item.customer.customerName)
      let id="select"+index
      console.log(id)
      let redoReason =document.getElementById(id).value
      console.log(redoReason)
      const {data: res}= await this.$http.get('/redoApplication/addNewApplication?customerName='+item.customer.customerName
      +'&redoReason='+redoReason+'&applicantAccount='+localStorage.getItem('applicantAccount'))
      if (res.data===0){
        alert('申请成功')
      }else {
        alert('申请失败')
      }
    }

  },




  created() {
    this.getAllList()
  }

}


</script>

<style lang="less" scoped>
.container1 {
  margin: 20px auto;
  max-width: 700px;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}


.container2 {
  margin: 20px auto;
  max-width: 1400px;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
</style>
